from data_preprocessing import DataPreprocessor
from load_prediction import LoadPredictor
from anomaly_detection import AnomalyDetector

def main():
    # 初始化数据预处理器
    preprocessor = DataPreprocessor('nwdaf_data.csv')
    
    # 准备负载预测数据
    print("准备负载预测数据...")
    X_train, X_test, y_train, y_test, feature_cols = preprocessor.prepare_data()
    
    # 训练和评估负载预测模型
    print("训练负载预测模型...")
    predictor = LoadPredictor()
    predictor.train_models(X_train, y_train)
    load_results = predictor.evaluate_models(X_test, y_test)
    
    print("\n负载预测结果:")
    for model, metrics in load_results.items():
        print(f"\n{model}:")
        for metric, value in metrics.items():
            print(f"{metric}: {value:.4f}")
    
    # 准备异常检测数据
    print("\n准备异常检测数据...")
    X_train, X_test, y_train, y_test, _ = preprocessor.prepare_anomaly_detection_data()
    
    # 训练和评估异常检测模型
    print("训练异常检测模型...")
    detector = AnomalyDetector()
    detector.train_models(X_train, y_train)
    anomaly_results = detector.evaluate_models(X_test, y_test)
    
    print("\n异常检测结果:")
    for model, metrics in anomaly_results.items():
        print(f"\n{model}:")
        for metric, value in metrics.items():
            print(f"{metric}: {value:.4f}")

if __name__ == "__main__":
    main() 